﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;


namespace EFCoreLenarn
{
    public class ArticleConfig : IEntityTypeConfiguration<Article>
    {
        public void Configure(EntityTypeBuilder<Article> builder)
        {
            builder.ToTable("T_Article");
            builder.Property(a => a.Content).IsRequired().IsUnicode();
            builder.Property(a => a.Title).IsRequired().IsUnicode().HasMaxLength(255);

        }
    }

    public class CommentConfig : IEntityTypeConfiguration<Comment>
    {
        public void Configure(EntityTypeBuilder<Comment> builder)
        {
            builder.ToTable("T_Comment");
            builder.HasOne<Article>(c => c.Article).WithMany(a => a.Comments).IsRequired().HasForeignKey(c=>c.ArticleId);
            builder.Property(c => c.Message).IsRequired().IsUnicode();
        }
    }
}
